package com.kwok.openplatform.controller;

import com.github.pagehelper.PageInfo;
import com.kwok.openplatform.common.result.TableData;
import com.kwok.openplatform.entity.Router;
import com.kwok.openplatform.service.RouterService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 路由表(Router)表控制层
 *
 * @author Kwok
 * @since 2024-07-21 18:31:38
 */
@RestController
@RequestMapping("/router")
public class RouterController {

    Log log = LogFactory.getLog(RouterController.class);

    @Autowired
    private RouterService routerService;

    @GetMapping("/pageList")
    public TableData<Router> pageList(Integer page, Integer limit, Router router){
        PageInfo<Router> pageInfo = routerService.queryRouters(page,limit,router);
        log.info("分页数据："+pageInfo.getList());
        TableData<Router> tableData = new TableData<>(0,"成功状态",pageInfo.getTotal(),pageInfo.getList());
        return tableData;
    }

    @PostMapping("/save")
    public String save(Router router){
        Integer integer = routerService.saveRouter(router);
        log.debug("新增了"+integer+"条记录");
        return integer + "";
    }

    @PostMapping("/update")
    public String update(Router router){
        Integer integer = routerService.updateRouterById(router);
        log.debug("修改了"+integer+"条记录");
        return integer + "";
    }

    @DeleteMapping("/remove/{id}")
    public String remove(@PathVariable Integer id){
        Integer integer = routerService.removeRouterById(id);
        log.debug("删除了"+integer+"条记录");
        return integer + "";
    }

    @PostMapping("/batchDelete")
    public String delete(Integer... ids){
        Integer integer = routerService.batchRemoveRouterById(ids);
        log.debug("批量删除了"+integer+"条记录");
        return integer + "";
    }

}

